package net.xiaosaguo.ssoclient.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * description: 客户端提供的接口
 *
 * @author xiaosaguo
 * @date 2020/07/07
 */
@Controller
public class HelloController {

    /**
     * description: 设定此接口无需登录即可访问
     *
     * @author xiaosaguo
     * @date 2020/07/07 18:21
     */
    @GetMapping("/hello")
    @ResponseBody
    public String hello() {
        return "hello";
    }

    /**
     * description: 设定此接口需登录，才能访问
     *
     * @author xiaosaguo
     * @date 2020/07/07 18:21
     */
    @GetMapping("/employees")
    public String employees(Model model, HttpSession session) {
        Object loginUser = session.getAttribute("loginUser");
        if (loginUser == null) {
            // 没登录，跳转到登录服务器进行登录
            return "";
        }
        List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        model.addAttribute("emps", list);
        return "list";
    }
}
